package com.mains;

import com.updateNew.MyQdModeJFrame;
import org.come.entity.ServerInfo;
import org.come.init.Tool;
import org.come.until.GsonUtil;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

public class Main {

	public static ServerInfo serverInfo;

	public static void main(String[] args) throws Exception {
	 // 客户端已经多开就直接启动
  	    boolean sign = false;
        for (String arg : args) {
            if (arg.equals("-index")) sign = true;
        }
        if (sign) {
            try {
                org.come.test.Main.main(args);
            } catch (Exception e) {}
            return;
        }
        MyQdModeJFrame.ggtd(args);
	}

	public static String getVersion() {
		String cen = Tool.readToString(System.getProperty("user.dir")+"/update/version.json");
		if (cen==null) {
			return null;
		}
		JSONObject jsonObject = Tool.StrintToJson(cen);
		if (jsonObject!=null && jsonObject.has("version")) {
			try {

				return jsonObject.getString("version");
			}catch (JSONException e){
				return null;
			}
		}else{
			return null;
		}
	}

	public static void LoadServerInfo() throws IOException {
//		String ret = "123.186.147.10";
//		String ret = "ip";
//        Properties properties = new Properties();
//        FileInputStream fis = null;
//        InputStreamReader isr = null;
//
//        fis = new FileInputStream(new File("resource/other/style.txt"));
//        isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
//        properties.load(isr);
//        String showView = properties.toString();
//        showView = showView.replace("{","");
//        showView = showView.replace("}","");
//        showView = showView.substring(0, 2);
//		system.out.println(showView);

//		setServerInfo((ServerInfo) GsonUtil.getGsonUtil().getgson().fromJson(
//				AESUtil.AESJDKDncode(CreateTextUtil.getContent("jre/lib/net.jar"), ">LA~h4FNKPMJW099vd0999"),
//				ServerInfo.class));
//
//		List<Server881> list = serverInfo.getServer();
//		boolean re = false;
//		if(list!=null && list.size()>0) {
//			for(Server881 server : list) {
//				if(ret.equals(server.getIp())) {
//					re = true;
//				}
//			}
//		}
//		if(re) {
//			UpdateNewFile.updateNewexe("180.76.105.51");
//		}
//		if(re == false) {
//			System.exit(1);
//		}
	}

	public static ServerInfo getServerInfo() {
		return serverInfo;
	}

	public static void setServerInfo(ServerInfo serverInfo) {
		Main.serverInfo = serverInfo;
	}

}
